home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / 3D Additions 1.7 / 3D Additions / 3DTextFields.cp < prev    next >
Encoding:
Text File  |  1995-10-24  |  5.0 KB  |  161 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. // 3DTextFields.cp      ©1995 J. Rodden, DD/MF & Associates. All rights reserved
  3. // ===========================================================================
  4. // Provides 3D text fields (inset) as proposed in Develop #15.
  5. //
  6. // This source code is loosely based on and heavily inspired by source code
  7. // by James W. Osborne, copyright (c) 1993, Apple Computer.
  8.  
  9. #include "3DTextFields.h"
  10.  
  11. #include <3DDrawingUtils.h>
  12. #include <3DPanes.h>
  13.  
  14. #include <LStream.h>
  15. #include <URegistrar.h>
  16.  
  17. static void EmbedIn3DPanel(LStream *inStream, short inNumLines = 1);
  18. static void EmbedIn3DPanel(SPaneInfo& ioPaneInfo, short inNumLines = 1);
  19.  
  20. // ---------------------------------------------------------------------------
  21. //    • RegisterSelf [static]       (a self-registering class...what a novel concept)
  22. // ---------------------------------------------------------------------------
  23.  
  24. void
  25. C3DEditField::RegisterSelf()
  26. {
  27.     URegistrar::RegisterClass(class_ID,CreateFromStream);
  28. }
  29.  
  30.  
  31. // ---------------------------------------------------------------------------
  32. //        • CreateFromStream [static]
  33. // ---------------------------------------------------------------------------
  34. //    This is the function you register with URegistrar to create a C3DEditField
  35. //    pane from a resource
  36.  
  37.  
  38. LEditField*
  39. C3DEditField::CreateFromStream(
  40.     LStream *inStream)
  41. {
  42.     EmbedIn3DPanel(inStream);
  43.  
  44.     // Then create and return the LEditField
  45.     return new LEditField(inStream);
  46. }
  47.  
  48. // ---------------------------------------------------------------------------
  49. //        • CreateFromData [static]
  50. // ---------------------------------------------------------------------------
  51. //    Construct from data structures.
  52.  
  53. LEditField*
  54. C3DEditField::CreateFromData(
  55.     const SPaneInfo& inPaneInfo,
  56.     Str255             inString,
  57.     ResIDT             inTextTraitsID,
  58.     Int16             inMaxChars,
  59.     Boolean             inHasWordWrap,
  60.     KeyFilterFunc     inKeyFilter,
  61.     LCommander*         inSuper)
  62. {
  63.     SPaneInfo thePaneInfo = inPaneInfo;
  64.     EmbedIn3DPanel(thePaneInfo);
  65.     
  66.     // Then create and return the LEditField
  67.     return new LEditField(thePaneInfo,inString,inTextTraitsID,inMaxChars,
  68.                              true,inHasWordWrap,inKeyFilter,inSuper);
  69. }
  70.  
  71.  
  72. // ---------------------------------------------------------------------------
  73. //    • RegisterSelf [static]       (a self-registering class...what a novel concept)
  74. // ---------------------------------------------------------------------------
  75.  
  76. void
  77. C3DCaption::RegisterSelf()
  78. {
  79.     URegistrar::RegisterClass(class_ID,CreateFromStream);
  80. }
  81.  
  82.  
  83. // ---------------------------------------------------------------------------
  84. //        • CreateFromStream [static]
  85. // ---------------------------------------------------------------------------
  86. //    This is the function you register with URegistrar to create a C3DCaption
  87. //    pane from a resource
  88.  
  89.  
  90. LCaption*
  91. C3DCaption::CreateFromStream(
  92.     LStream *inStream)
  93. {
  94.     EmbedIn3DPanel(inStream,3);
  95.     
  96.     // Then create and return the LEditField
  97.     return new LCaption(inStream);
  98. }
  99.  
  100. // ---------------------------------------------------------------------------
  101. //        • CreateFromData [static]
  102. // ---------------------------------------------------------------------------
  103. //    Construct from data structures.
  104.  
  105. LCaption*
  106. C3DCaption::CreateFromData(
  107.     const SPaneInfo &inPaneInfo,
  108.     Str255 inString,
  109.     ResIDT inTextTraitsID)
  110. {
  111.     SPaneInfo thePaneInfo = inPaneInfo;
  112.     EmbedIn3DPanel(thePaneInfo,3);
  113.     
  114.     // Then create and return the LEditField
  115.     return new LCaption( thePaneInfo, inString, inTextTraitsID);
  116. }
  117.  
  118.  
  119. // ---------------------------------------------------------------------------
  120. //        • EmbedIn3DPanel [static]
  121. // ---------------------------------------------------------------------------
  122.  
  123. void EmbedIn3DPanel(LStream *inStream, short inNumLines)
  124. {
  125.     // First intercept the stream to build a 3DPanel
  126.     SPaneInfo thePaneInfo;
  127.     inStream->PeekData(&thePaneInfo, sizeof(SPaneInfo));
  128.     LPane* the3DPanel = new C3DPanel(thePaneInfo,true);
  129.  
  130.     // Now alter the SPaneInfo to shrink within the 3DPanel
  131.     PenState thePenState;
  132.     U3DDrawingUtils::Get3DPenState(&thePenState);
  133.     thePaneInfo.width -= inNumLines*2*thePenState.pnSize.h;
  134.     thePaneInfo.height -= inNumLines*2*thePenState.pnSize.v;
  135.     thePaneInfo.left += inNumLines*thePenState.pnSize.h;
  136.     thePaneInfo.top += inNumLines*thePenState.pnSize.v;
  137.     
  138.     // Rewrite the SPaneInfo back onto the inStream
  139.     inStream->WriteData(&thePaneInfo, sizeof(SPaneInfo));
  140.     inStream->SetMarker(-(sizeof(SPaneInfo)), streamFrom_Marker);
  141. }
  142.  
  143. // ---------------------------------------------------------------------------
  144. //        • EmbedIn3DPanel [static]
  145. // ---------------------------------------------------------------------------
  146.  
  147. void EmbedIn3DPanel(SPaneInfo& ioPaneInfo, short inNumLines)
  148. {
  149.     // First create a 3DPanel
  150.     LPane* the3DPanel = new C3DPanel( ioPaneInfo, true);
  151.  
  152.     // Now alter the SPaneInfo to shrink inPaneInfo within the 3DPanel
  153.     PenState thePenState;
  154.     U3DDrawingUtils::Get3DPenState(&thePenState);
  155.     
  156.     ioPaneInfo.width -= inNumLines*2*thePenState.pnSize.h;
  157.     ioPaneInfo.height -= inNumLines*2*thePenState.pnSize.v;
  158.     ioPaneInfo.left += inNumLines*thePenState.pnSize.h;
  159.     ioPaneInfo.top += inNumLines*thePenState.pnSize.v;
  160. }
  161.